﻿Imports System.Data.SqlClient

Public Class clsCot_Detalle
    Private mintIdDetalle As Integer
    Private mintidGeneral As Integer
    Private mintIdProducto As Integer
    Private mstrCodigo As String
    Private mstrProducto As String
    Private mdblCantidad As Double
    Private mdblPU As Double
    Private mdblSubTotal As Double
    Private mdblIVA As Double
    Private mdblTotal As Double
    Public Property IdDetalle() As Integer
        Get
            Return mintIdDetalle
        End Get
        Set(ByVal value As Integer)
            mintIdDetalle = value
        End Set
    End Property
    Public Property IdGeneral() As Integer
        Get
            Return mintidGeneral
        End Get
        Set(ByVal value As Integer)
            mintidGeneral = value
        End Set
    End Property
  
    Public Property IdProducto() As Integer
        Get
            Return mintIdProducto
        End Get
        Set(ByVal value As Integer)
            mintIdProducto = value
        End Set
    End Property
    Public Property Codigo() As String
        Get
            Return mstrCodigo
        End Get
        Set(ByVal value As String)
            mstrCodigo = value
        End Set
    End Property
    Public Property Producto() As String
        Get
            Return mstrProducto
        End Get
        Set(ByVal value As String)
            mstrProducto = value
        End Set
    End Property

    Public Property Cantidad() As Double
        Get
            Return mdblCantidad
        End Get
        Set(ByVal value As Double)
            mdblCantidad = value
        End Set
    End Property
    Public Property PU() As Double
        Get
            Return mdblPU
        End Get
        Set(ByVal value As Double)
            mdblPU = value
        End Set
    End Property
    Public Property SubTotal() As Double
        Get
            Return mdblSubTotal
        End Get
        Set(ByVal value As Double)
            mdblSubTotal = value
        End Set
    End Property
    Public Property IVA() As Double
        Get
            Return mdblIVA
        End Get
        Set(ByVal value As Double)
            mdblIVA = value
        End Set
    End Property
    Public Property Total() As Double
        Get
            Return mdblTotal
        End Get
        Set(ByVal value As Double)
            mdblTotal = value
        End Set
    End Property
    Public Sub New()
        mintIdDetalle = 0
        mintidGeneral = 0
        mintIdProducto = 0
        mstrCodigo = ""
        mstrProducto = ""
        mdblCantidad = 0
        mdblPU = 0
        mdblSubTotal = 0
        mdblIVA = 0
        mdblTotal = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into Cot_Detalle (" & _
                            "IdGeneral," & _
                            "IdProducto," & _
                            "Codigo," & _
                            "Producto," & _
                            "Cantidad," & _
                            "PU," & _
                            "SubTotal," & _
                            "IVA," & _
                            "Total)" & _
                            "VALUES (" & _
                            "@IdGeneral," & _
                            "@IdProducto," & _
                            "substring(@Codigo,1,20)," & _
                            "substring(@Producto,1,300)," & _
                            "@Cantidad," & _
                            "@PU," & _
                            "@SubTotal," & _
                            "@IVA," & _
                            "@Total)" & _
                            " SELECT SCOPE_IDENTITY()"

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdGeneral", mintidGeneral)
        Command.Parameters.AddWithValue("IdProducto", mintIdProducto)
        Command.Parameters.AddWithValue("Codigo", mstrCodigo)
        Command.Parameters.AddWithValue("Producto", mstrProducto)
        Command.Parameters.AddWithValue("Cantidad", mdblCantidad)
        Command.Parameters.AddWithValue("PU", mdblPU)
        Command.Parameters.AddWithValue("SubTotal", mdblSubTotal)
        Command.Parameters.AddWithValue("IVA", mdblIVA)
        Command.Parameters.AddWithValue("Total", mdblTotal)


        cnConn.Open()
        IdDetalle = Convert.ToInt32(Command.ExecuteScalar)

        If IdDetalle > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro detalle ", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
End Class
